package cvsexercise9;

/* Create the Triangle class declaration according to the UML
 * by creating a subclass of the Shape class
 * include (private) instance variables to store the base and height (double)
 * include a constructor that calls the superclass constructor 
 * include a getter method to return the base (double) - getBase()
 * include a getter method to return the width (double) - getHeight()
 * include an override the getArea() method to return the area of the triangle (0.5 x base x height)
 * include an override the toString() method to output the type of subclass (i.e. "subclass of super.toString()")
 */
public class Triangle extends Shape {

	/* private instance variables */
	private double base;
	private double height;
	
	/* constructor (takes a string and two double parameters) */
	public Triangle(String colour, double base, double height) {
		
		/* call the superclass constructor, passing the string as an argument */
		super(colour);
		
		/* set the classes private instance variables */
		this.base = base;
		this.height = height;
	}
	
	/* getter method to return the base (as a double) */
	public double getBase() {
		return base;
	}
	
	/* getter method to return the height (as a double) */
	public double getHeight() {
		return height;
	}
	
	/* override the getArea() method to return the area of the triangle (double) */
	@Override
	public double getArea() {
		return (0.5 * base * height);
	}
	
	/* override the toString() method to write out the type of superclass */
	@Override 
	public String toString() {
		return ("Triangle is a subclass of " + super.toString());
	}

}
